﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharacterModel
{
    private static CharacterModel _instance;

    public static CharacterModel Instance
    {
        get
        {
            if (_instance == null)
                _instance = new CharacterModel();
            return _instance;
        }
    }
   
    public List<CharacterSqliteData> CharacterDatas = new List<CharacterSqliteData>();
    public List<ItemData> ItemDatas = new List<ItemData>();

    ///初始化数据  保存从服务器读取到的数据
    public void LoadData(SqlDbConnect sqliteDbconn)
    {
        CharacterDatas = sqliteDbconn.SelectAll<CharacterSqliteData>();
        ItemDatas = sqliteDbconn.SelectAll<ItemData>();
    }
    
    /// <summary>
    /// 存储数据
    /// </summary>
    /// <param name="sqliteDbconn"></param>
    public void SaveData(SqlDbConnect sqliteDbconn)
    {
       sqliteDbconn.Update<CharacterSqliteData>(CharacterDatas.ToArray());
       sqliteDbconn.Update<ItemData>(ItemDatas.ToArray());
        Debug.Log("存储成功");
    }
}
